package com.mou.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mou.dto.ChatBoxDTO;
import com.mou.dto.MessageQueryDTO;
import com.mou.entity.ChatBox;
import com.mou.entity.Message;
import com.mou.vo.ChatBoxVO;
import com.mou.vo.MessageVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ChatMapper extends BaseMapper<Message> {
    @Select("select id from message where sender_id = #{senderId} and receiver_id = #{receiverId} and content = #{content} ")
    List<Integer> getId(Message message);


    List<MessageVO> getMessages(MessageQueryDTO messageQueryDTO);

    @Select("update message set status = 3 where sender_id = #{currentId} and receiver_id = #{receiverId}")
    void markMessageAsRead(@Param("currentId") Integer currentId,@Param("receiverId") Integer id);

    @Select("select * from chat_box where sender_id = #{currentId}")
    List<ChatBox> getChatBox(Integer currentId);

    @Select("insert into chat_box (sender_id, receiver_id, create_time, update_time) values (#{senderId}, #{receiverId},#{createTime}, #{updateTime})")
    void addChatBox(ChatBox chatBox);

    @Select("update chat_box set update_time = #{updateTime} where sender_id = #{senderId} and receiver_id = #{receiverId}")
    void updateChatBox(ChatBox chatBox);
    @Select("select count(*) from chat_box where sender_id = #{senderId} and receiver_id = #{receiverId}")
    Integer existsChatBox(ChatBoxDTO chatBoxDTO);

    @Select("select count(*) from message where receiver_id = #{receiverId} and sender_id = #{currentId} and status = 1")
    Integer getUnReadMessageCount(@Param("currentId") Integer currentId,@Param("receiverId") Integer receiverId);
}
